﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>InputBox - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The InputBox function displays an input box to ask the user to enter a string." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>InputBox</h1>

<p>Displays an input box to ask the user to enter a string.</p>

<pre class="Syntax">Obj := <span class="func">InputBox</span>(<span class="optional">Prompt, Title, Options, Default</span>)</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Prompt</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The text of the input box, which is usually a message to the user indicating what kind of input is expected. If <em>Prompt</em> is long, it can be broken up into several shorter lines by means of a <a href="../Scripts.htm#continuation">continuation section</a>, which might improve readability and maintainability.</p>
  </dd>

  <dt>Title</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The title of the input box. If omitted, it defaults to the current value of <a href="../Variables.htm#ScriptName">A_ScriptName</a>.</p>
  </dd>

  <dt>Options</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
      <p>A string of case-insensitive options, with each separated from the last by a space or tab.</p>
      <p><strong>Xn Yn:</strong> The X and Y coordinates of the dialog. 例如, <em>X0 Y0</em> puts the window at the upper left corner of the desktop. If either coordinate is omitted, the dialog will be centered in that dimension. Either coordinate can be negative to position the dialog partially or entirely off the desktop (or on a secondary monitor in a multi-monitor setup).</p>
      <p><strong>Wn Hn:</strong> The width and height of the dialog's client area, which excludes the title bar and borders. For example, <em>W200 H100</em>.</p>
      <p><strong>T:</strong> Specifies the timeout in seconds. For example, <em>T10.0</em> is ten seconds. If this value exceeds 2147483 (24.8 days), it will be set to 2147483. After the timeout has elapsed, the InputBox window will be automatically closed and <a href="#return">Result</a> will be set to word "Timeout". <a href="#return">Value</a> will still contain what the user entered.</p>
      <p><strong>Password:</strong> Mask the user's input. To specify which character is used, follow this example: <em>Password*</em></p>
  </dd>

  <dt>Default</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>A string that will appear in the InputBox's edit field when the dialog first appears. The user can change it by backspacing or other means.</p>
  </dd>

</dl>

<h2 id="return">返回值</h2>
<p>Type: <a href="../objects/Object.htm">Object</a></p>
<p>This function returns an object with the following properties:</p>
<ul>
  <li><code>Value</code> (<a href="../Concepts.htm#strings">String</a>): The text entered by the user.</li>
  <li><code>Result</code> (<a href="../Concepts.htm#strings">String</a>): One of the following words indicating how the InputBox was closed: "OK", "Cancel", "Timeout".</li>
</ul>

<h2 id="Remarks">备注</h2>
<p>An input box usually looks like this:</p>
<img src="../static/dlg_input.png" alt="InputBox" />
<p>The dialog allows the user to enter text and then press OK or CANCEL. The user can resize the dialog window by dragging its borders.</p>
<p>A GUI window may display a modal InputBox by means of <a href="../objects/Gui.htm#OwnDialogs">OwnDialogs option</a>. A modal InputBox prevents the user from interacting with the GUI window until the InputBox is dismissed.</p>
<h2 id="Related">相关</h2>
<p><a href="../objects/Gui.htm">Gui object</a>, <a href="MsgBox.htm">MsgBox</a>, <a href="FileSelect.htm">FileSelect</a>, <a href="DirSelect.htm">DirSelect</a>, <a href="ToolTip.htm">ToolTip</a>, <a href="InputHook.htm">InputHook</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExPassword">
<p><a href="#ExPassword">#1</a></p>
<pre>password := InputBox("(your input will be hidden)", "Enter Password", "password").value</pre>
</div>

<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#2</a></p>
<pre>IB := InputBox("Please enter a phone number.", "Phone Number", "w640 h480")
if IB.Result = "Cancel"
    MsgBox "You entered '" IB.Value "' but then cancelled."
else
    MsgBox "You entered '" IB.Value "'."</pre>
</div>

</body>
</html>